package cn.itsource.ymcc.web.controller;

import cn.itsource.ymcc.dto.AlipayNotifyDto;
import cn.itsource.ymcc.dto.PayDto;
import cn.itsource.ymcc.result.JSONResult;
import cn.itsource.ymcc.service.IPayOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private IPayOrderService payOrderService;

    @RequestMapping(value = "/checkPayOrder/{orderNO}",method = RequestMethod.GET)
    public JSONResult checkPayOrder(@PathVariable("orderNO")String orderNO){
        // 由serveice 层响应 JSONResult，成功或失败
        return payOrderService.checkPayOrder(orderNO);
    }



    @RequestMapping(value = "/apply",method = RequestMethod.POST)
    public JSONResult apply(@RequestBody @Valid  PayDto payDto){
        String html = payOrderService.apply(payDto);
        return JSONResult.success(html);
    }


    @RequestMapping(value = "/alipay/notify",method = RequestMethod.POST)
    public String alipayNotify(@Valid  AlipayNotifyDto alipayNotifyDto){

        return payOrderService.alipayNotify(alipayNotifyDto);
    }



}
